package com.kotlin.flong.reflection

import kotlin.reflect.KMutableProperty1
import kotlin.reflect.full.createInstance
import kotlin.reflect.full.declaredMemberProperties

/**
 * @Author:liangjl
 * @Date: 2020/7/12-8:52
 * @Eamil:jilongliang@sina.com
 * @Description:
 */
class MyTest14() {
    var name: String = "GoLanguage"
    var price: Double = 37.0
}

fun main() {

    var classz = MyTest14::class
    var instace = classz.createInstance()
    var properties = classz.declaredMemberProperties

    properties.forEach {
        when (it.name) {
            "name" -> {
                var kmp = it as KMutableProperty1<MyTest14, Any>
                //name=Spark
                kmp.set(instace, "Spark")
                println(it.get(instace))
            }
            "price" -> {
                println(it.get(instace))
            }
        }
    }

}